//
//  CollectionCellTwo.m
//  喜马拉雅FM
//
//  Created by dllo on 16/1/26.
//  Copyright © 2016年 lanou.com. All rights reserved.
//
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT UIScreen mainScreen].bounds.size.height

#import "CollectionCellTwo.h"
#import "SubCollectionCellOne.h"
#import "ModelForCollectionViewTwo.h"
#import "SubCollectionViewCellTwo.h"
#import "SubCollectionCellThree.h"
#import "SubCollectionCellFour.h"



@interface CollectionCellTwo ()<UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@end

@implementation CollectionCellTwo

- (void)dealloc {

    [_collection release];
    [_arrForCollectionViewTwo release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {

        [self createCollectionView];
    }
    return self;
}

- (void)setArrForCollectionViewTwo:(NSMutableArray *)arrForCollectionViewTwo {

        [arrForCollectionViewTwo retain];
        [_arrForCollectionViewTwo release];
        _arrForCollectionViewTwo = arrForCollectionViewTwo;
        [self.collection reloadData];
}

#pragma mark createCollectionView
- (void)createCollectionView {
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayout.itemSize = CGSizeMake(WIDTH,(WIDTH - 30)/2 + 25);
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 5;

    self.collection = [[UICollectionView alloc]initWithFrame: self.bounds collectionViewLayout:flowLayout];
    [self.contentView addSubview:self.collection];
    self.collection.backgroundColor = [UIColor whiteColor];
    self.collection.dataSource = self;
    self.collection.delegate = self;
    [self.collection registerClass:[SubCollectionCellOne class] forCellWithReuseIdentifier:@"poolForSubCollectionViewCell"];
    [self.collection registerClass:[SubCollectionViewCellTwo class] forCellWithReuseIdentifier:@"poolForSubCollectionViewCellTwo"];
    [self.collection registerClass:[SubCollectionCellThree class] forCellWithReuseIdentifier:@"poolForSubCollectionViewCellThree"];
    [self.collection registerClass:[SubCollectionCellFour class] forCellWithReuseIdentifier:@"poolForSubCollectionViewCellFour"];
    [self.collection release];

}

#pragma mark UICollectionViewDelegateFlowLayout协议方法.

#pragma mark collectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.item == 0) {
        SubCollectionCellOne *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"poolForSubCollectionViewCell" forIndexPath:indexPath];
       
        [cell passModelForCellOne:self.arrForCollectionViewTwo];
        return cell;
    }
    
    
   else if (indexPath.item == 1) {
        SubCollectionViewCellTwo *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"poolForSubCollectionViewCellTwo" forIndexPath:indexPath];
        [cell passModelForCellTwo:self.arrForCollectionViewTwo];
        return cell;
    }
   else if (indexPath.item == 2) {
       SubCollectionCellThree *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"poolForSubCollectionViewCellThree" forIndexPath:indexPath];
       [cell passModelForCellThree:self.arrForCollectionViewTwo];
       return cell;
    }
   else {
       SubCollectionCellFour *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"poolForSubCollectionViewCellFour" forIndexPath:indexPath];
       [cell passModelForCellFour:self.arrForCollectionViewTwo];
       return cell;
    }
}

@end
